//获取主机id和IP地址
const os = require("os");

function getNetworkIp() {
  let needHost = ""; // 打开的host
  try {
    // 获得网络接口列表
    let network = os.networkInterfaces();
    for (let dev in network) {
      let iface = network[dev];
      for (let i = 0; i < iface.length; i++) {
        let alias = iface[i];
        if (alias.family === "IPv4" && alias.address !== "127.0.0.1" && !alias.internal) {
          needHost = alias.address;
        }
      }
    }
  } catch (e) {
    needHost = "localhost";
  }
  return needHost;
}

const myHost = getNetworkIp();
const myName = os.hostname();
process.env.VUE_APP_HOST = myHost;//IP地址
process.env.VUE_APP_NAME = myName;//主机名
//生成设备id
const idObj = require("node-machine-id");
let id = idObj.machineIdSync({ original: true });

process.env.VUE_APP_MACHINEID = id;//设备id
console.log("当前IP地址:",myHost);
console.log("当前主机名：" , process.env.VUE_APP_NAME);
console.log("当前设备id：" , process.env.VUE_APP_MACHINEID);